import { BasicColumn } from '@/components/Table';
import { FormSchema } from '@/components/Table';
import { rules } from '@/utils/helper/validator';
import { defHttp } from '/@/utils/http/axios';

//列表数据
export const columns: BasicColumn[] = [
  {
    title: '用户',
    align: "center",
    dataIndex: 'userId_dictText'
  },
  {
    title: '设备',
    align: "center",
    dataIndex: 'thingsUserId_dictText'
  },
  {
    title: '邮箱',
    align: "center",
    dataIndex: 'email'
  },
  {
    title: '电话',
    align: "center",
    dataIndex: 'phone'
  },
  {
    title: '系统通知',
    align: "center",
    dataIndex: 'systemNotice',
    customRender: ({ text }) => {
      return text === 0 ? '是' : '否';
    }
  },
  {
    title: '邮件通知',
    align: "center",
    dataIndex: 'emailNotice',
    customRender: ({ text }) => {
      return text === 0 ? '是' : '否';
    }
  },
  {
    title: '短信通知',
    align: "center",
    dataIndex: 'smsNotice',
    customRender: ({ text }) => {
      return text === 0 ? '是' : '否';
    }
  },
  {
    title: '使用系统信息',
    align: "center",
    dataIndex: 'systemInfo',
    customRender: ({ text }) => {
      return text === 0 ? '是' : '否';
    }
  }
];

//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: '用户ID',
    field: 'userId',
    component: 'Input'
  },
  {
    label: '邮箱',
    field: 'email',
    component: 'Input'
  },
  {
    label: '电话',
    field: 'phone',
    component: 'Input'
  }
];

//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '用户',
    field: 'userId',
    component: 'JSelectUser',
    required: true,
    componentProps: {
      labelKey: 'realname',
      rowKey: 'id',
      isRadioSelection: true
    }
  },
  {
    label: '设备',
    field: 'thingsUserId',
    component: 'ApiSelect',
    required: true,
    componentProps: {
      api: () => defHttp.get({ url: '/thingsUserDevice/list' }).then((res) => {
        return res.data.map((item) => ({
          label: item.name,
          value: item.thingsUserDevice.id
        }));
      })
    }
  },
  {
    label: '邮箱',
    field: 'email',
    component: 'Input',
    rules: [{ ...rules.email }]
  },
  {
    label: '电话',
    field: 'phone',
    component: 'Input',
    rules: [{ pattern: /^1[3456789]\d{9}$/, message: '请输入正确的手机号码' }]
  },
  {
    label: '系统通知',
    field: 'systemNotice',
    component: 'RadioButtonGroup',
    defaultValue: 0,
    componentProps: {
      options: [
        { label: '是', value: 0 },
        { label: '否', value: 1 }
      ]
    }
  },
  {
    label: '邮件通知',
    field: 'emailNotice',
    component: 'RadioButtonGroup',
    defaultValue: 0,
    componentProps: {
      options: [
        { label: '是', value: 0 },
        { label: '否', value: 1 }
      ]
    }
  },
  {
    label: '短信通知',
    field: 'smsNotice',
    component: 'RadioButtonGroup',
    defaultValue: 0,
    componentProps: {
      options: [
        { label: '是', value: 0 },
        { label: '否', value: 1 }
      ]
    }
  },
  {
    label: '使用系统信息',
    field: 'systemInfo',
    component: 'RadioButtonGroup',
    defaultValue: 0,
    componentProps: {
      options: [
        { label: '是', value: 0 },
        { label: '否', value: 1 }
      ]
    }
  },
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false
  }
];

/**
* 流程表单调用这个方法获取formSchema
* @param param
*/
export function getBpmFormSchema(_formData): FormSchema[] {
  return formSchema;
}
